import QtQuick 2.15

Item {
    id:root
    width: 50
    property alias bgcolor: bgItem.color
    property alias textcolor: textItem.color
    property alias text: textItem.text
    property bool en: true
    property int aX0
    property int aY0
    property int aX1
    property int aY1
    property alias show: showAnimation
    property alias hide: hideAnimation
    signal hided()
    signal clicked()
    height: width
    Rectangle {
        id: bgItem
        anchors.fill: parent
        radius: width / 2
        color: en ? "#EEFFFFFF" : "#55FFFFFF"
        Text {
            id: textItem
            anchors.centerIn: parent
            color: en ?"#AA000000": "#55FFFFFF"
            text: qsTr("AM")
            font.pixelSize: (parent.width / 2) * 0.7
            font.bold: true
        }
    }
    MouseArea{
        anchors.fill: parent
        onPressed: root.scale = 0.8
        onReleased: root.scale = 1
        onClicked: root.clicked()
    }
    ParallelAnimation {
        id: showAnimation
        NumberAnimation {
            target: root
            property: "x"
            from:aX0
            to: aX1
            duration: 300
            easing.type: Easing.InOutQuad
        }

        NumberAnimation {
            target: root
            property: "y"
            from:aY0
            to: aY1
            duration: 300
            easing.type: Easing.InOutQuad
        }
        NumberAnimation {
            target: root
            property: "scale"
            from:0.2
            to: 1
            duration: 200
            easing.type: Easing.InOutQuad
        }
    }


    ParallelAnimation {
        id: hideAnimation
        NumberAnimation {
            target: root
            property: "x"
            from:aX1
            to: aX0
            duration: 300
            easing.type: Easing.InOutQuad
        }

        NumberAnimation {
            target: root
            property: "y"
            from:aY1
            to: aY0
            duration: 300
            easing.type: Easing.InOutQuad

        }
        NumberAnimation {
            target: root
            property: "scale"
            from:1
            to: 0.2
            duration: 200
            easing.type: Easing.InOutQuad

        }
        onStopped: root.hided()
    }

}
